#include <stdio.h>
#include <math.h>

void swap(double, double);
void testArray();
void testArr2(int n);
void tesTwoDimensionalArray();

int main() {
    printf("hello world\n");
    int i = 10;
    printf("i = %d\n", i);

    int double_size = sizeof(double);
    printf("double size = %d\n", double_size);

    float a, b, c;

    a = 1.234567;
    b = 1.111111;
    c = a + b;
    if (c == 2.345678)
    {
        printf("equal\n");
    } else {
        printf("not equal\n");
    }
    
    // 函数调用
    swap(1, 21);

    // 数组
    int gradeNum = 100;
    int grades[gradeNum];
    for (size_t i = 0; i < 10; i++)
    {
        grades[i] = i;
    }
    for (size_t i = 0; i < 10; i++)
    {
        int data = grades[i];
        printf("data = %d\n", data);
    }
    
    // testArray();
    // testArr2(10);
    tesTwoDimensionalArray();
    
    return 0;
}

int a() {
    printf("www");
    return 0;
}



void swap(double aa, double bb) {
    printf("swap a=%f, b=%f", aa, bb);
}

void testArray() {
    int count[10];
    for (size_t i = 0; i < 10; i++)
    {
        count[i] = 0;
    }

    int arrSize = sizeof(count) / sizeof(count[0]);
    printf("arrSize = %d", arrSize);

    int num;
    while (1)
    {
        scanf("%d", &num);
        if (num == -1)
        {
            break;
        }
        
        if (num >= 0 && num <= 9)
        {
            count[num] ++;
        }
        
    }
    
    for (int i = 0; i < 10; i++)
    {
        printf("%d出现的次数%d\n", i, count[i]);
    }
}

int isPrime(int n) {
    for (int i = 2; i <= sqrt(n); i++)
    {
        if (n % i == 0)
        {
            return 0;
        }
        
    }
    
    return 1;
}

/**
 * @brief 求前n个素数
 * 
 * @param n 
 */
void testArr2(int n) {
    int arr[n];
    int cnt = 1;
    arr[0] = 2;
    int counter = 3;
    while (cnt < n)
    {
        if (isPrime(counter))
        {
            arr[cnt++] = counter;
        }
        
        counter++;
    }

    for (int i = 0; i < n; i++)
    {
        printf("\t%d", arr[i]);
    }
    printf("\n");
    
}

void tesTwoDimensionalArray() {
    int arr[][5] = {
        {1, 2, 3, 4, 5},
        {2, 3, 4, 5, 6},
    };
    for (int i = 0; i < 2; i++)
    {
        for (int j = 0; j < 5; j++)
        {
            printf("[%d][%d]=%d\t", i, j, arr[i][j]);
        }
        printf("\n");
        
    }
    
}
